package ASE;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Conntoller {
      
	public List<Booking> bookingListfromfile ;
	public Que<Booking> queue ;
	public int count ;
	public Desk desk ;
	public GUI gui ;
	public int unckecked ;
	
	public Conntoller ()
	{
	  bookingListfromfile = new ArrayList<Booking > () ;
		this.count = 0 ;
		this.unckecked = 0 ;
	}
	
	
	public static void main(String[] args) throws FileNotFoundException {
		
		Conntoller controler = new Conntoller();
		controler.GetLisFromFile();
		if(controler.unckecked>0)
		controler.gui= new GUI(controler.bookingListfromfile  ,controler.unckecked );
		controler.bookingListfromfile = controler.gui.BookingList ;
		controler.startQueue();
		controler.desk = new Desk (controler.queue);
	}

	public void GetLisFromFile(){ 
	      try{
	    // Open the file that is the first 
	    // command line parameter
	    FileInputStream fstream = new FileInputStream("BookingFile.txt");
	    // Get the object of DataInputStream
	    DataInputStream in = new DataInputStream(fstream);
	        BufferedReader br = new BufferedReader(new InputStreamReader(in));
	    String strLine;
	    //Read File Line By Line
	    
	    while ((strLine = br.readLine()) != null)   {
	     
	    	String Book [] = strLine.split(";");
	    	if(Book.length==7)
	    	{
	    	Luggage L = new Luggage(Double.parseDouble(Book[2]), Double.parseDouble(Book[3]), Double.parseDouble(Book[4]), Double.parseDouble(Book[5]));
	    	Passenger P = new Passenger(Book[1],L);
	    	Booking b = new Booking (Book[0], P ,Book[6]);
	    	if(Book[6].contains("no")){unckecked++ ;}
	    	this.bookingListfromfile.add(count, b);
	    	System.out.println(Book[6] + "   "+unckecked);
	    	}
	    	else 
	    	{
	    		System.err.println("Error: line "+count+"invalid input" );break ; 
	    	}
	 
	    	count++ ;
	    }
	    //Close the input stream
	    in.close();
	    
	    }catch (Exception e){//Catch exception if any
	      System.err.println("Error: " + e.getMessage());
	    }
	  }
	public void startQueue(){
		if(count>0)
		{
		this.queue = new Que<Booking>();
		
		for (int x=0 ; x<count ;x++) 
		 {  
			 Booking b = bookingListfromfile.get(x);
			 this.queue.enqueue(b);
		 }
		}
		else 
		{
		 System.out.println("The List Is Empty ");	
		}
	}
	

	

}
